package com.wanmait.hr.controller;

import com.wanmait.hr.service.MemuService;
import com.wanmait.hr.vo.Memu;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Controller

/**
 * Demo class
 *
 * @author chen
 * @date 2019/1/22
 */
public class MemuSettingsController {

    @Resource
    private MemuService memuService;

    /**侧边栏设置*/
    @RequestMapping("/manage/memu_settings/list")
    public void getSidebar(){
    }

    /**一级菜单设置*/
    @ResponseBody
    @RequestMapping(value = "/manage/memu_settings/update_bigType",method = RequestMethod.GET)
    public ModelAndView updateBigType(HttpServletRequest request){
        ModelAndView mv = new ModelAndView();
        List<Memu> memu = memuService.findBigType();
        return mv.addObject("BigTypeSettings",memu);
    }

    /**二级菜单设置*/
    @ResponseBody
    @RequestMapping(value = "/manage/memu_settings/update_smallType",method = RequestMethod.GET)
    public ModelAndView updateSmallType(){
        ModelAndView mv = new ModelAndView();
        List<Memu> memu = memuService.findAll();
        return mv.addObject("SmallTypeSettings",memu);
    }

    /**禁用列表设置*/
    @ResponseBody
    @RequestMapping(value = "/manage/memu_settings/update_disableList",method = RequestMethod.GET)
    public ModelAndView updateDisabledList(){
        ModelAndView mv = new ModelAndView();
        List<Memu> memu = memuService.findDisabled();
        System.out.println("%**********************%");
        return mv.addObject("disabledList",memu);
    }

    @ResponseBody
    @RequestMapping(value = "/manage/memu_settings/update_bigType/updateName",method = RequestMethod.GET)
    public void updateBigTypeName(Memu memu){
        memuService.updateBigTypeName(memu);
    }

    @ResponseBody
    @RequestMapping(value = "/manage/memu_settings/update_bigType/updataBigTypeSort",method = RequestMethod.GET)
    public void updataBigTypeSort(Memu memu){
        memuService.updateBigTypeSort(memu);
    }

    @ResponseBody
    @RequestMapping(value = "/manage/memu_settings/update_bigType/updataBigTypeUrl",method = RequestMethod.GET)
    public void updataBigTypeUrl(Memu memu){
        memuService.updateBigTypeUrl(memu);
    }

    @ResponseBody
    @RequestMapping(value = "/manage/memu_settings/update_bigType/deleteChecked",method = RequestMethod.GET)
    public void deleteChecked(String ids){
        ids = ids.substring(1).replace(" ","");
        String[] id = ids.split(",");
        for (String zid : id) {
            memuService.deleteChecked(Integer.parseInt(zid));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/manage/memu_settings/update_bigType/deleteSingle",method = RequestMethod.GET)
    public void deleteSingle(Integer id){
        memuService.deleteChecked(id);
    }

    @ResponseBody
    @RequestMapping(value = "/manage/memu_settings/update_bigType/disable_list",method = RequestMethod.GET)
    public void disableList(Integer id){
        memuService.disableList(id);
    }

    @ResponseBody
    @RequestMapping(value = "/manage/memu_settings/update_bigType/disable_list_all",method = RequestMethod.GET)
    public void disableListAll(String ids){
        ids = ids.substring(1).replace(" ","");
        String[] id = ids.split(",");
        for (String zid : id) {
            memuService.disableList(Integer.parseInt(zid));
        }
    }
}
